using System;
using System.Collections.Generic;
using System.Text;
using TrainTicket.DAO;
using TrainTicket.VO;
using System.Data;

namespace TrainTicket.TRAIN
{
    public class SeatTRAIN
    {
        private SeatDAO _seatDAO;
        public SeatTRAIN()
        {
            _seatDAO = new SeatDAO();
        }

        public DataTable GetAllSeat()
        {
            return _seatDAO.GetAllSeat();
        }

        public DataTable GetAllSeatByTrainRouter(ListTrain listTrain)
        {
            return _seatDAO.GetAllSeatByTrainRouter(listTrain);
        }

        public bool GetStatusSeat(int seatID)
        {
            DataTable dTable = _seatDAO.GetStatusSeat(seatID);
            Seat seat = new Seat();
            foreach (DataRow dr in dTable.Rows)
            {
                seat.Status = dr["Status"].ToString();
            }
            if (seat.Status == "No Book Seat" || seat.Status.Equals("No Book Seat"))
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public Seat GetSeatById(int seatID)
        {
            List<Seat> list = new List<Seat>();
            DataTable dTable = _seatDAO.GetSeatById(seatID);
            Seat seat = new Seat();
            foreach (DataRow dr in dTable.Rows)
            {
                seat.SeatID = Convert.ToInt32(dr["SeatID"].ToString());
                seat.ListTrainID = Convert.ToInt32(dr["ListTrainID"].ToString());
                seat.NumberSeat = dr["NumberSeat"].ToString();
                seat.Status = dr["Status"].ToString();
            }
            return seat;
        }

        public bool CheckSeatExitsUpdate(int listBusID, string numberSeat)
        {
            int check = _seatDAO.CheckSeatExitsUpdate(listBusID, numberSeat);
            if (check > 0)
                return true;
            else
                return false;
        }

        public int UpdateSeat(int seatID, string numberSeat)
        {
            return _seatDAO.UpdateSeat(seatID, numberSeat);
        }


        public DataTable SearchSeat(int listBusID, string numberSeat, string status)
        {
            return _seatDAO.SearchSeat(listBusID, numberSeat, status);
        }

    }
}
